import { create } from 'zustand'

const useUserStore = create((set) => ({
    username: '',
    token: '',
    setUser: (username, token) => set({ username, token }),
    clearUser: () => set({ username: '', token: '' })
}))

export default useUserStore

/*
    使用示例：

    import React from 'react'
    import { View, Button, Text } from '@tarojs/components'
    import useUserStore from '@/store/userStore'

    export default function UserPage() {
        const { username, setUser, clearUser } = useUserStore()

        return (
            <View>
            <Text>当前用户：{username || '未登录'}</Text>
            <Button onClick={() => setUser('张三', 'token-abc')}>
                登录
            </Button>
            <Button onClick={clearUser}>
                退出登录
            </Button>
            </View>
        )
    }
*/
